﻿@{
    ViewBag.Title = "RoleCheck";
}
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <script src="@Url.Content("~/ScriptPlugin/WdatePicker/js/WdatePicker.js")"></script>
    <script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
}
<div id="grid">
   
</div>
@section foot{
    <script type="text/javascript">
        function LoadUserInfoData() {
            var columns = [[
                    { field: "ck", checkbox: true},
                    { field: "Name", title: "角色名称", width: 130 },
                    { field: "IsAdmin", title: "是否管理员角色", width: 100 },
                    { field: "IsSystem", title: "是否系统角色", width: 90 }
            ]];
            var parameter = {
                title: null,
                columns: columns,
                url: "@Url.Content("~/Sys/Role/GetRoleGridData")",
                pageNumber: 1,
                onCheck: checkRow,
                onUncheck: uncheckRow,
                onCheckAll: checkAllRow,
                onUncheckAll: uncheckAllRow,
                onLoadSuccess:loadSuccess
            };
            var grid = K.GetGridData("#grid", parameter).Grid;
        }
        LoadUserInfoData();
        var checkedRows = new Array();
        function loadSuccess()
        {
            var rows = $("#grid").datagrid("getRows");
            $.Enumerable.From(rows).ForEach(function (row,i) {
                if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == row.Id; }).Count() != 0) {
                    $("#grid").datagrid("checkRow", i);
                }
            });
        }
        function checkRow(rows,rowData)
        {
           if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() == 0)
           {
               checkedRows = $.Enumerable.From(checkedRows).Union([rowData]).ToArray();
           }
        }
        function uncheckRow(rows, rowData)
        {
            if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() > 0) {
                checkedRows = $.Enumerable.From(checkedRows).Except([rowData]).ToArray();
            }
        }
        function checkAllRow(rows)
        {
            checkedRows = $.Enumerable.From(checkedRows).Union(rows).ToArray();
        }
        function uncheckAllRow(rows)
        {
            checkedRows = $.Enumerable.From(checkedRows).Except(rows).ToArray();
        }
        function SaveData(index)
        {
            parent.K.layer.callback(index, checkedRows);
            parent.K.layer.close(index);
        }
    </script>
}